﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyHocBongSinhVien.DAO
{
    class Khoa_DAO
    {
        dbConnection db = new dbConnection();
       public DataTable getAllKhoa()
       {
           return db.ExecuteQuery("Select * from Khoa");
       }
       public DataTable getMakhoa()
       {
           string sql = "select Makhoa,TenKhoa from Khoa";
           return db.ExecuteQuery(sql);
       }

       public void ThemKhoa(string Ma, string ten, string TruongKh, int Sdt, string email)
       {
           SqlParameter[] mang = new SqlParameter[5];
           mang[0] = new SqlParameter("@MaKhoa", Ma);
           mang[1] = new SqlParameter("@TenKhoa", ten);
           mang[2] = new SqlParameter("@TruongKhoa", TruongKh);
           mang[3] = new SqlParameter("@SDT", Sdt);
           mang[4] = new SqlParameter("@Email", email);
           db.ExecuteNonQuery("ThemKhoa", mang);
       }

       public void SuaKhoa(string Ma, string ten, string TruongKh, int Sdt, string email)
       {
           SqlParameter[] mang = new SqlParameter[5];
           mang[0] = new SqlParameter("@MaKhoa", Ma);
           mang[1] = new SqlParameter("@TenKhoa", ten);
           mang[2] = new SqlParameter("@TruongKhoa", TruongKh);
           mang[3] = new SqlParameter("@SDT", Sdt);
           mang[4] = new SqlParameter("@Email", email);
           db.ExecuteNonQuery("SuaKhoa", mang);
       }

       public void XoaKhoa(string ma)
       {
           SqlParameter[] mang = new SqlParameter[1];
           mang[0] = new SqlParameter("@MaKhoa", ma);
           db.ExecuteNonQuery("Xoa_Khoa", mang);
       }

       public DataTable TimKiemTheoMa(string ma)
       {
           SqlParameter[] mang =new SqlParameter[1];
           mang[0] = new SqlParameter("@MaKhoa",ma);
           return db.ExecuteQuery("TimKiem_Khoa",mang);
       }

       public DataTable TimKiemTheoTenKhoa(string ma)
       {
           SqlParameter[] mang = new SqlParameter[1];
           mang[0] = new SqlParameter("@tenkhoa ", ma);
           return db.ExecuteQuery("TimKiem_TenKhoa", mang);
       }
       public DataTable TimKiemTheoTruongKhoa(string ma)
       {
           SqlParameter[] mang = new SqlParameter[1];
           mang[0] = new SqlParameter(" @truongkhoa ", ma);
           return db.ExecuteQuery("TimKiem_TruongKhoa", mang);
       }

       public DataTable TimKiemTheoSDT(int ma)
       {
           SqlParameter[] mang = new SqlParameter[1];
           mang[0] = new SqlParameter(" @sodt ", ma);
           return db.ExecuteQuery("TimKiemTheo_SDThoai", mang);
       }
       public DataTable TimKiemTheoEmail(string ma)
       {
           SqlParameter[] mang = new SqlParameter[1];
           mang[0] = new SqlParameter("  @email ", ma);
           return db.ExecuteQuery("TimKiem_email", mang);
       }
    }
}
